package com.lemon.system.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import com.lemon.system.domain.BiElements;
import com.lemon.system.service.IBiElementsService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.page.TableDataInfo;

/**
 * 包名称：com.lemon.system.controller
 * 类名称：BiElementsController
 * 类描述：要素信息Controller
 * 创建人：@author huangpeng
 * 创建时间：2023-03-12
 */
@RestController
@RequestMapping("/elements")
public class BiElementsController extends BaseController {

    @Autowired
    private IBiElementsService biElementsService;

    /**
     * 查询要素信息列表
     * @Title: list
     * @Description: 查询要素信息列表
     * @param biElements 要素信息
     * @return: TableDataInfo
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elements:list")
    @GetMapping("/list")
    public TableDataInfo list(BiElements biElements) {
        startPage();
        List<BiElements> list = biElementsService.selectBiElementsList(biElements);
        return getDataTable(list);
    }

    /**
     * 导出要素信息列表
     * @Title: export
     * @Description: 导出要素信息列表
     * @param response 客户端响应对象
     * @param biElements 要素信息
     * @return:
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elements:export")
    @Log(title = "要素信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BiElements biElements) {
        List<BiElements> list = biElementsService.selectBiElementsList(biElements);
        ExcelUtil<BiElements> util = new ExcelUtil<BiElements>(BiElements.class);
        util.exportExcel(response, list, "要素信息数据");
    }

    /**
     * 获取要素信息详细信息
     * @Title: getInfo
     * @Description: 获取要素信息详细信息
     * @param id 要素信息主键
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elements:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(biElementsService.selectByPrimaryKey(id));
    }

    /**
     * 新增要素信息
     * @Title: add
     * @Description: 新增要素信息
     * @param biElements 要素信息
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elements:add")
    @Log(title = "要素信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BiElements biElements) {
        return toAjax(biElementsService.insert(biElements));
    }

    /**
     * 修改要素信息
     * @Title: edit
     * @Description: 修改要素信息
     * @param biElements 要素信息
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elements:edit")
    @Log(title = "要素信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BiElements biElements) {
        return toAjax(biElementsService.update(biElements));
    }

    /**
     * 删除要素信息
     * @Title: remove
     * @Description: 删除要素信息
     * @param ids 需要删除的要素信息主键集合
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elements:remove")
    @Log(title = "要素信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(biElementsService.deleteByBatch(ids));
    }

    /**
     * 保存要素信息
     * @Title: saveElements
     * @Description: 保存要素信息
     * @param list
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/3/12 21:25
     */
    @RequiresPermissions("system:elements:add")
    @Log(title = "要素信息", businessType = BusinessType.INSERT)
    @PostMapping("saveElements")
    public AjaxResult saveElements(@RequestBody List<BiElements> list) {
        return toAjax(biElementsService.saveElements(list));
    }

    /**
     * 获取系统配置信息
     * @Title: getSiteConfig
     * @Description: 获取系统配置信息
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/8/2 18:58
     */
    @GetMapping("getSiteConfig")
    public AjaxResult getSiteConfig() {
        Map<String, Object> configList = biElementsService.getSiteConfig();
        return AjaxResult.success(configList);
    }
}
